<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>原生Js交互之DSBridge</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=0.5,user-scalable=no"/>
    <!--require dsbridge init js-->
    <script src="https://unpkg.com/dsbridge/dist/dsbridge.js"> </script>
    <style>
        .btn {
            text-align: center;
            background: #d8d8d8;
            color: #222;
            padding: 20px;
            margin: 30px;
            font-size: 24px;
            border-radius: 4px;
            box-shadow: 4px 2px 10px #999;
        }

        .btn:active {
            opacity: .7;
            box-shadow: 4px 2px 10px #555;
        }
    </style>
</head>
<body>
<div id="syn" class="btn" type="submit" οnclick="callSyn()">Synchronous call</div>
<div id="asyn" class="btn" οnclick="callAsyn()">Asynchronous call</div>
<div id="receive" class="btn" οnclick="callAsynjsToNative()">jsToNative</div>
<div id="txt_id" class="txt" ></div>
<script>
 document.getElementById('syn').onclick = callSyn;
  document.getElementById('asyn').onclick = callAsynjsToNative;
   document.getElementById('receive').onclick = callAsynjsToNative;
 
    function callSyn() {
	
	 console.log("999999999")
	 dsBridge.call("testSyn", "testSyn",function (res){
	 alert("testSyn")
	  console.log(res)
	 });
    }
	
	      function callAsynjsToNative() {
        dsBridge.call("testAsyn", "testAsyn",function (asyn) {
            alert("asyn")
			 console.log(asyn)
        })
    }
	
	      function callAsynjsToNative() {
        dsBridge.call("jsToNative", "jsToNative",function (jsToNative) {
            alert("jsToNative")
			 console.log(jsToNative)
        })
    }
	
	 var txtMsg = document.getElementById('txt_id');
    dsBridge.register('nativeToJs', function (name,msg) {
      txtMsg.innerHTML=msg+" "+name;
        return msg;
    })

</script>
</body>
</html>